const express = require('express');
const router = express.Router();
const db = require('../config/db');

// 获取商品详情
router.get('/:id', async (req, res) => {
    try {
        const { id } = req.params;
        const [goods] = await db.query('SELECT * FROM goods WHERE id = ?', [id]);
        
        if (goods.length === 0) {
            return res.status(404).json({ message: '商品不存在' });
        }
        
        res.json(goods[0]);
    } catch (error) {
        console.error('获取商品详情失败:', error);
        res.status(500).json({ message: '获取商品详情失败' });
    }
});

module.exports = router;